﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设备组管理</title>
    <meta name="decorator" content="nblank"/>
</head>
<body>
<div class="content container">
    <h2 class="page-title">设备组管理
        <small> 设备${not empty param.id?'修改':'添加'}</small>
    </h2>
    <section class="widget widget-tabs widget-table-overflow ">
        <header>
            <ul class="nav nav-tabs">
                <li><a href="${ctx}/biz/equgroup/list">设备组列表</a></li>
                <li><a href="${ctx}/biz/equgrpitem/list?group.id=${item.group.id}">组设备列表&nbsp(${item.group.name})</a></li>
                <li class="active"><a href="${ctx}/biz/equgrpitem/form?group.id=${item.group.id}">设备${not empty param.id?'修改':'添加'}&nbsp(${item.group.name})</a></li>
            </ul>
        </header>
        <div class="body tab-content">
            <form:form id="inputForm" modelAttribute="item" action="${ctx}/biz/equgrpitem/save" method="post" class="form-horizontal">
                <form:hidden path="id"/>
                <form:hidden path="group.id" value="${item.group.id}"/>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span>设备名称:</span></label>
                    <div class="col-sm-4">
                        <form:input path="name" htmlEscape="false" maxlength="50" class="form-control input-transparent"/>
                        <label id="kidScan" class="error" style="display: none;">名称已存在，请重填</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span>设备类型:</span></label>
                    <div class="col-sm-4">
                        <form:select path="equipment.id" items="${equipList}" data-style="btn-primary" data-width="auto" class="selectpicker" itemValue="id" itemLabel="name" />
                    </div>
                </div>
                <div class="form-actions">
                    <div class="text-align-center">
                        <input id="btnCancel" class="btn btn-default" type="button" style="margin-left: -50px;min-width:100px;" value="返 回" onClick="history.go(-1)"/>
                        <input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;" type="submit" value="保 存"/>&nbsp;
                    </div>
                </div>
            </form:form>
        </div>
    </section>
</div>
<script type="text/javascript">
    var $name = $("#name");
    var $kidScan = $("#kidScan");
    var $inputForm = $("#inputForm");
    var $btnSubmit = $("#btnSubmit");
    $(function () {
        $name.focus(function () {
            $kidScan.css("display", "none");
        });
        $inputForm.validate({
            ignore: "",
            focusInvalid : true,
            rules: {
                name: "required",
            },
            invalidHandler: function () {
                $btnSubmit.attr("disabled", false);
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function (form) {
//                $(form).find(":submit").attr("disabled", true).attr("value", "提交中...");
                $(form).ajaxSubmit({
                    success: function (result) {
                        switch (result){
                            case "success":
                                Messenger().post("操作成功!");
                                pxTrigDlg("${ctx}/biz/equgrpitem/list?group.id="+$("#group\\.id").val());
                                break;
                            case "errorName":
                                $kidScan.css("display", "block");
                                break;

                        }
                    }
                })
            }
        });
    });
</script>

</body>
</html>